<?php

	require('connect.php');
	$id = $_POST['id-edit'];
	$fecha = date('Y-m-d h:i:s');
	$readTime = date('A');
	$ano = date('Y');
	$mes = date('m');
	$dia = date('d');
	$opening = $_POST['gallons-edit'];
	$product = $_POST['product-edit'];
	$water = $_POST['water-edit'];
	$sales = $_POST['sales-edit'];
	$gross = $_POST['gross-edit'];
	$so    = $_POST['so-edit'];
	$sa    = $_POST['sa-edit'];
	$hoses = $_POST['hoses-edit'];
	$nozzles = $_POST['nozzles-edit'];
	$dispensers = $_POST['dispensers-edit'];
	$comments = $_POST['comments-edit'];
	$tank = $_POST['tank-edit'];
	switch($tank) {
		case 'CLR DSL':
			$tankid='BCD8091EBFE8483AA7749DC7CF66C23C';
			break;
		case 'GASOLINE 87 OCT E-10 UNLEADED':
			$tankid='F2858F8E8A93474698407F080CD6B061';
			break;
		case 'GASOLINE 93 OCT E-10 HITEST':
			$tankid='CA7200DE3FFD4C24BC7BC2C5F6EBD787';
			break;
	}
if($id!=' '){

	$query = "update EnvironmentalDaily set OpenGal='$opening',ProdNo='$product',
	Water='$water',Sales='$sales',GalDeliv='$gross',SystemOperating='$so',SystemAlarm='$sa',
	HosesOK='$hoses',NozzlesOK='$nozzles',DispensersOK ='$dispensers',Comments='$comments',TankID='$tankid'
		where ID='$id'";
sqlsrv_query($conn, $query);

}else{
	//$query = "select MAX(id_num+1) as ID from EnvironmentalDailyNew";
	//$result = sqlsrv_query($query);
	//while($row = sqlsrv_fetch_array($result)) {		
		//$id = $row['ID'];
	//}
	/* $query="insert into EnvironmentalDaily (ReadTime,OpenGal,ProdNo,Water,Sales,GalDeliv,TrnDate,SystemOperating,SystemAlarm,
	HosesOK,NozzlesOK,DispensersOK ,Comments,TankID,TrnYr,TrnMonth,TrnDay) values('$readTime','$opening','$product','$water','$sales','$gross','$fecha','$so','$sa','$hoses','$nozzles','$dispensers','$comments','$tankid','$ano','$mes','$dia')";

*/

$sql = "INSERT INTO EnvironmentalDaily (ReadTime,OpenGal,ProdNo,Water,Sales,GalDeliv,TrnDate,SystemOperating,SystemAlarm,
	HosesOK,NozzlesOK,DispensersOK ,Comments,TankID,TrnYr,TrnMonth,TrnDay) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$params = array($readTime,$opening,$product,$water,$sales,$gross,$fecha,$so,$sa,$hoses,$nozzles,$dispensers,$comments,$tankid,$ano,$mes,$dia);

sqlsrv_query( $conn, $sql, $params);
}


sqlsrv_close($conn);